{extend name="layout" /}
{block name="title"}编辑链接{/block}
{block name="style"} <style>
    .layui-btn-small {
        padding: 0 15px;
    }

    .layui-form-checkbox {
        margin: 0;
    }

    tr td:not(:nth-child(0)),
    tr th:not(:nth-child(0)) {
        text-align: center;
    }

    #dataConsole {
        text-align: center;
    }
    /*分页页容量样式*/
    /*可选*/
    .layui-laypage {
        display: block;
    }

    /*可选*/
    .layui-laypage > * {
        float: left;
    }
    /*可选*/
    .layui-laypage .laypage-extend-pagesize {
        float: right;
    }
    /*可选*/
    .layui-laypage:after {
        content: ".";
        display: block;
        height: 0;
        clear: both;
        visibility: hidden;
    }

    /*必须*/
    .layui-laypage .laypage-extend-pagesize {
        height: 30px;
        line-height: 30px;
        margin: 0px;
        border: none;
        font-weight: 400;
    }
    /*分页页容量样式END*/
</style>{/block}
{block name="body"}
<div style="margin-bottom:5px;">
    <span class="layui-breadcrumb" >
  <a href="{:url('/admin/friendLink')}">首页</a>
  <a><cite>编辑链接</cite></a>
</span>
</div>
<blockquote class="layui-elem-quote layui-text">
    编辑链接
</blockquote>

<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">链接名</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="required" autocomplete="off" placeholder="请输入链接名" class="layui-input" value="{$data.name}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">url</label>
        <div class="layui-input-block">
            <input type="tel" name="url" lay-verify="url" autocomplete="off" class="layui-input" placeholder="http://www.baidu.com" value="{$data.url}">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-upload">
            <label class="layui-form-label">上传LOGO</label>
            <div class="layui-input-block" style="position: relative;">
                <div style="position: absolute;top:45%;left:5%;"><input type="file" name="file" class="layui-upload-file" id="upload" ></div>

                <div class="layui-upload-list">
                    <img class="layui-upload-img" id="uploadImg" src="{$data.logo}" style="width:250px;height:250px;border-radius: 50%;">
                    <input type="hidden" name="logo" id="logo" value="{$data.logo}">
                </div>
            </div>

        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input type="number" name="order"  autocomplete="off" class="layui-input" placeholder="排序" value="{$data.order}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-block">
            <button class="layui-btn" style="width:230px;" lay-submit="" lay-filter="edit">编辑</button>
        </div>
    </div>
</form>
{/block}
{block name="script"}
<!-- layui规范化用法 -->
<script type="text/javascript">
    var id = {$id};
    layui.define(['form','element','upload'],function(){
        var form = layui.form();

        layui.upload({
            url: baseUrl+"api/uploadImg" //上传接口
            ,success: function(res){ //上传成功后的回调
                $("#uploadImg").attr('src',res.data.imgUrl);
                $("#logo").val(res.data.imgUrl);
            }
        });

        $('body').keydown(function (e) {
            if (e.keyCode == 13) {  //Enter键
                $('button[lay-filter=edit]').click();
            }
        });

        form.on('submit(edit)', function(data){
            var index = layer.load(1);
            var url = baseUrl+"api/friendLink/"+id;
            var data = $('form').serialize();
            urlAjax(url,data,function(data){
                    layer.close(index);
                    if(data.status){
                        layer.msg(data.info, { icon: 5 });
                    }else{
                        layer.msg(data.info, { icon: 6 });
                        layer.closeAll('page');
                        setTimeout(function(){
                            top.location.href = data.url;
                        },1500);
                    }
                },
                function(){
                    layer.close(index);
                    layer.msg('网络错误，请重试', { icon: 5 });
                },'PUT');
            return false;
        });
    });
</script>

{/block}